package com.mujin.keji.collectionsystem.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;

/**
 * 选择交通工具
 *
 * @author weishixiong
 * @Time 2018-05-10
 */


public class SelectTrrificPopWindow extends PopupWindow {
    private Activity context;
    private TextView tvBus;
    private TextView tvCommonBus;
    private TextView tvBike;
    private SelectLisenter selectLisenter;
    private RelativeLayout parent;
    /**
     * 交通工具选择
     */
    public interface SelectLisenter {
        // 1 驾车 2公交 3骑行
        void onSelectTrrifi(int type);
    }

    /**
     * @param context
     */
    public SelectTrrificPopWindow(final SelectLisenter selectLisenter, final Activity context) {
        this.context = context;
        this.selectLisenter = selectLisenter;
        //获得 LayoutInflater 的实例
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.pop_select_ttraffic, null);
        this.setContentView(contentView);
        tvBus = (TextView) contentView.findViewById(R.id.tv_bus);
        tvCommonBus = (TextView) contentView.findViewById(R.id.tv_common_bus);
        tvBike = (TextView) contentView.findViewById(R.id.tv_bike);
        parent = (RelativeLayout) contentView.findViewById(R.id.parent);
        tvBus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectLisenter.onSelectTrrifi(1);
            }
        });
        tvCommonBus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectLisenter.onSelectTrrifi(2);
            }
        });
        tvBike.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectLisenter.onSelectTrrifi(3);
            }
        });

        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

        this.setFocusable(true);
        this.setOutsideTouchable(true);
//        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(Color.parseColor("#80000000"));
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        setBackgroundDrawable(dw);
    }

}
